/*
 * @author M.T. Segarra
 * @version 0.0.1
 */
package tests;

import static org.junit.Assert.*;
import org.junit.*;
import java.util.*;

import subscribersManagement.Subscriber;
import loansManagement.Loan;
import outils.StringCalendar;
import booksManagement.Book;
import exceptions.*;

public class BookTest {

	private Subscriber s;
	private Book b;
	private ArrayList<String> authors;
	
	@Before
	public void beforeTests() throws BadParametersException {
		StringCalendar sc=new StringCalendar();
		s = new Subscriber("Mayte", "Segarra", sc.calendarToString(new GregorianCalendar(2000,12,13)), sc.calendarToString(new GregorianCalendar(2000,12,13)));
		
		authors = new ArrayList<String>();
		authors.add("Corral");
		b = new Book("Fundamentals of Database Systems", new GregorianCalendar(),  "0-321-20228-4", 3, authors);
	}
	
	@Test
	public void testEqualsObject() throws BadParametersException {
		Book b2 = new Book("Fundamentals of Database Systems", new GregorianCalendar(), "0-321-20228-4", 3, authors);
		assertTrue(b.equals(b2));
		
		b2 = new Book("Fundamentals of Database Systems", new GregorianCalendar(), "0-87320-568-1", 2, authors);
		assertFalse(b.equals(b2));
		
		b2 = new Book("SQL-99 Complete, Really", new GregorianCalendar(), "0-321-20228-4", 2, authors);
		assertTrue(b.equals(b2));
	}

	@Test
	public void testOKBook() throws BadParametersException {
		new Book("SQL-99 Complete, Really", new GregorianCalendar(), "0-87930-568-1", 2, authors);
	}
	
	@Test(expected = BadParametersException.class)
	public void testNullBook() throws BadParametersException{
		new Book("Noche", new GregorianCalendar(), null, 1, authors);
		/*authors = null;
		new Book(null, authors, new GregorianCalendar(), "020178515");
		new Book("Noche", authors, null, "020178515");
		new Book("Noche", authors, new GregorianCalendar(), null);*/
	}
	
	@Test
	public void testLendBook() throws BadParametersException, 
	TooManyLoansException, LentMediaException, NoMoreSpecimensExeption{
		Loan spec = new Loan(b,s);
		assertTrue(spec.getReturned() != null);
	}
	
	@Test(expected = NoMoreSpecimensExeption.class)
	public void testLendLentBook() throws BadParametersException, 
	TooManyLoansException, LentMediaException, NoMoreSpecimensExeption{
		StringCalendar sc=new StringCalendar();
		s= new Subscriber("Mayte", "Seg", sc.calendarToString(new GregorianCalendar(2000,12,13)), sc.calendarToString(new GregorianCalendar(2000,12,13)));
		new Loan(b,s);
		s= new Subscriber("Mayt", "Seg", sc.calendarToString(new GregorianCalendar(2000,12,13)), sc.calendarToString(new GregorianCalendar(2000,12,13)));
		new Loan(b,s);
		s= new Subscriber("May", "Seg", sc.calendarToString(new GregorianCalendar(2000,12,13)), sc.calendarToString(new GregorianCalendar(2000,12,13)));
		new Loan(b,s);
		s= new Subscriber("Ma", "Seg", sc.calendarToString(new GregorianCalendar(2000,12,13)), sc.calendarToString(new GregorianCalendar(2000,12,13)));
		new Loan(b,s);
	}
	
	@Test
	public void testReturnBook() throws BadParametersException, 
	TooManyLoansException, LentMediaException, NoMoreSpecimensExeption{
		Loan spec = new Loan(b,s);
		spec.setReturned(true);
		assertTrue(spec.getReturned() == true);
	}
}
